#/bin/bash
sleep 2

apt-get update -y 1> /dev/null 2> /dev/null
clear
yum update -y 1> /dev/null 2> /dev/null
apt-get install openssh-server -y 1> /dev/null 2> /dev/null
clear
apt-get install curl -y 1> /dev/null 2> /dev/null
clear
yum install openssh-server -y 1> /dev/null 2> /dev/null
clear
apt-get install openssh-client -y 1> /dev/null 2> /dev/null
clear
yum install openssh-client -y 1> /dev/null 2> /dev/null
clear
apt-get install stunnel4 -y 1> /dev/null 2> /dev/null
clear
yum install stunnel4 -y 1> /dev/null 2> /dev/null
clear
apt-get install stunnel -y 1> /dev/null 2> /dev/null
clear
yum install stunnel -y 1> /dev/null 2> /dev/null
clear

ip=$(curl https://api.ipify.org/)
echo $ip
clear

sleep 1
echo -e "Generando Certificado..."
openssl genrsa 2048 > stunnel.key
openssl req -new -key stunnel.key -x509 -days 1000 -out stunnel.crt

sleep 2
rm /etc/stunnel/stunnel.conf
clear
rm /etc/default/stunnel4
clear
cat stunnel.crt stunnel.key > stunnel.pem 
mv stunnel.pem /etc/stunnel/
clear
figlet -p -f smslant < /root/name
echo -e " "
echo -e " "
echo -e "\033[1;37mESCRIBA EL PUERTO SSL A UTILIZAR"
read -p ": " port
clear
echo "client = no " >> /etc/stunnel/stunnel.conf
echo "[ssh] " >> /etc/stunnel/stunnel.conf
echo "cert = /etc/stunnel/stunnel.pem " >> /etc/stunnel/stunnel.conf
echo "accept = $port " >> /etc/stunnel/stunnel.conf
echo "connect = 127.0.0.1:22" >> /etc/stunnel/stunnel.conf
sleep 1
echo "ENABLED=1 " >> /etc/default/stunnel4
echo "FILES="/etc/stunnel/*.conf" " >> /etc/default/stunnel4
echo "OPTIONS="" " >> /etc/default/stunnel4
echo "PPP_RESTART=0" >> /etc/default/stunnel4
service stunnel4 restart
echo -e "\033[1;33m ───────────────────────────────────────"
echo -e "\033[1;37mI N I C I A N D O  -  STUNNEL4"
echo -e "\033[1;33m ───────────────────────────────────────"
sleep 1
service ssh restart 1>/dev/null 2 /dev/null
service stunnel4 start 1>/dev/null 2 /dev/null
service stunnel4 restart 1>/dev/null 2 /dev/null
clear
echo -e "\033[1;33m ***********REINICIADO...*************"
clear

echo -e "\033[1;33m ───────────────────────────────────────"
echo -e "\033[1;37mCONFIGURACION SSL CREADA CON EXITO"
echo -e "\033[1;33m ───────────────────────────────────────"
echo -e "\033[1;37m- - - - -> \033[01;31mSU IP HOST: $ip"
sleep 2
vpspack 10
